package com.wuseguang.springcloud.util;

/**
 *@描述 返回前端的信息
 *@返回值   result
 *@创建人  zm
 *@创建时间  2019/11/17
 */
public class Result<T> {

    private String code;

    private String msg;

    private T data;

    /**
     * 默认返回成功
     */
    public Result(){
        code = "200";
        msg ="成功";
    }

    /**
     * 成功，自定义提示
     * @param msg
     */
    public Result(String msg){
        this.code = "200";
        this.msg =msg;

    }

    /**
     * 返回信息。(一般只有错误才用到)
     * @param codeUtil
     */
    public Result(CodeUtil codeUtil) {
        this.code = String.valueOf(codeUtil.getCode()) ;
        this.msg = codeUtil.getMsg();
    }

    /**
     * 自定义返回。(一般只有错误才用到)
     * @param code
     * @param msg
     */
    public Result(Integer code,String msg ){
        this.code = String.valueOf(code) ;
        this.msg = msg;
    }

    /**
     * 返回失败带数据
     * @param codeUtil 错误信息
     * @param data 数据
     */
    public Result(CodeUtil codeUtil,T data){
        this.code = String.valueOf(codeUtil.getCode()) ;
        this.msg = codeUtil.getMsg();
        this.data = data;
    }

    /**
     * 返回成功带数据
     * @param data 数据
     */
    public Result(T data){
        this();
        this.data = data;
    }


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
